import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk'; // 异步处理模块
import logger from 'redux-logger'; // redux 日志模块
import mainReducer from './reducers';

const middlewares = [ // 三方模块通过该中间件注册
  thunkMiddleware
]

if (process.env.NODE_ENV === 'development') {
  middlewares.push(logger)
}

// Redux DevTools 配置
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

// 创建 store
const store = createStore(mainReducer, composeEnhancers(
  applyMiddleware(...middlewares)
));

// const store = createStore(mainReducer, applyMiddleware(...middlewares));

// 检测redux状态变化
store.subscribe(() => {
  console.log(' - redux 状态改变 - ', store.getState());
});

export default store